#pragma once
#include "common.h"
namespace srpc
{
    class RpcChannel : public google::protobuf::RpcChannel
    {
        public:
            inline RpcChannel() {}
            virtual ~RpcChannel(){}
            virtual void CallMethod(const  google::protobuf::MethodDescriptor* method,
                                google::protobuf::RpcController* controller, const google::protobuf::Message* request,
                                google::protobuf::Message* response, google::protobuf::Closure* done) = 0;
        
    };
    class TcpRpcChannel : public RpcChannel
    {
        public:
            inline TcpRpcChannel()
            {
                mpRpcMessagePB = new RpcMessagePB();
            }
            virtual ~TcpRpcChannel(){
            }
            void CallMethod(const  google::protobuf::MethodDescriptor* method,
                                    google::protobuf::RpcController* controller, const google::protobuf::Message* request,
                                    google::protobuf::Message* response, google::protobuf::Closure* done);
            void SetBufferEvent(int socket, EV_BASE evBase);
        private:
            static void read_cb(BUFEVENT bev, void *arg);
            static void error_cb(BUFEVENT bev, short event, void *arg);
            BUFEVENT mpBufferEvent;
            EV_BASE mpEvBase;
            google::protobuf::Closure *mpDone;
            RpcMessagePB* mpRpcMessagePB;
            google::protobuf::Message *mpRequest;
            google::protobuf::Message *mpResponse;
    };
}